import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;

public class Test {
    public static void main(String[] args) {
        
            try {
                FileInputStream i = new FileInputStream(new File("..\\p.jpg"));
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                byte[] chunk = new byte[8192];
                int len;
                while ((len = i.read(chunk)) != -1) {
                            buffer.write(chunk, 0, len);
                }
                byte[] a = buffer.toByteArray();
                i.read(a);
                for (int j = 0; j < 10; j++) {
                            OutputStream out = new FileOutputStream("..\\" + j + ".jpg") ;
                            out.write(a);
      }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
    }
}
